#include "../csapp.h"
#define N 2

void *fun(void *vargp);

char **ptr;

void test_sharing()
{
	int i;
	pthread_t tid;
	char *msg[N] = {
			"Hello from foo",
			"Hello from bar"
	};
	
	ptr = msg;
	for (i = 0; i < N; i++)
		Pthread_create(&tid, NULL, fun, (void *)i);
	Pthread_exit(NULL);
}

void *fun(void *vargp)
{
	int myid = (int)vargp;
	static int cnt = 0;
	printf("[%d]: %s (cnt=%d)\n", myid, ptr[myid], ++cnt);
	return (NULL);
}